#!/bin/bash -xe


install_dependencies() {
  apt-get update || true

  #Installing the following python dependencies
  pip install ipaddress || true
  pip3 install ipaddress || true

  apt-get -y install software-properties-common
  add-apt-repository ppa:ubuntu-toolchain-r/test -y
  apt-get update -y
  apt-get -y install build-essential m4
  apt-get install -y psmisc expect gdb

  ### Set symbolic link to linux headers to comply with uname-r on docker
  ln -s /lib/modules/* /lib/modules/$(uname -r)
}

install_dependencies

echo $http_proxy
echo $https_proxy
echo $ftp_proxy
echo $socks_proxy
echo $no_proxy
echo $ALL_PROXY

cat >> ~/.bashrc <<EOF
export http_proxy="http://proxy-dmz.intel.com:911"
export https_proxy="http://proxy-dmz.intel.com:912"
export ftp_proxy="ftp://proxy-dmz.intel.com:21"
export socks_proxy="proxy-dmz.intel.com:1080"
export no_proxy="intel.com,*.intel.com,localhost,127.0.0.1,10.0.0.0/8,192.168.0.0/16,172.16.0.0/12"
export ALL_PROXY='socks5://proxy-us.intel.com'
export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0"
EOF

cat >> ~/.ssh/config <<EOF
Host github.com
  proxycommand nc -x proxy-dmz.intel.com:1080 %h %p
  Port 22
  User git
  StrictHostKeyChecking no
EOF

cat ~/.bashrc

git config --global http.proxy http://proxy-dmz.intel.com:911
git config --global https.proxy https://proxy-dmz.intel.com:912
git config --global user.email "nobody@nowhere"
git config --global user.name "Jenkins"

# enable core dumps of user processes. Max size 10 GB.
ulimit -c 10000000
ulimit -c
ulimit -a
cat /proc/sys/kernel/core_*

sudo sysctl -w kernel.core_pattern=core.%e
echo "*               soft    core            unlimited" > /etc/security/limits.conf || true
systemctl restart apport || true
cat /etc/apport/crashdb.conf || true

cat /proc/sys/kernel/core_*
uname -a || true
lsb_release -a || true
grep HugePage /proc/meminfo || true
